<?php
include("../header.inc");
require_once("../DataBase.inc");
require_once("../applicants/view_script.inc");

require_once("exam_queries.inc");

$center_id = $_GET["exam_center_id"];

if (isset($_GET["confirm"]) && $_GET["confirm"] == "yes") {
	DataBase::delete("exam_center", array("exam_center_id"=>$center_id));
	echo "Exam center removed.";
	echo "<br/><br/>";
	echo "<a href='review_exam_centers.php'>Go back to the list of exam centers</a>";
	die();
}

$center = query_exam_centers_info($center_id)->execute();
$center = $center[0];
$nb = query_applicants_assigned_to_exam_center($center_id)->count();
?>
You asked to remove exam center <i><?php echo $center["exam_center_name"]?></i>.<br/>
<?php
if ($nb > 0) {
	echo "There is still ".$nb." applicants assigned to this exam center. Please assign them to another center before to remove the exam center: <a href='' onclick='list();return false;'>View list</a>";
	
} else {
	echo "Are you sure you want to remove this exam center ?<br/><br/>";
	echo "<a href='?exam_center_id=".$center_id."&confirm=yes'>YES</a>";
}
?>
<br/><br/>
<a href='review_exam_centers.php'>Go back to the list of exam centers</a>

<script type='text/javascript'>
function list() {
	view_applicants({
		"applicant.applicant_selection_id":false,
		"applicant.applicant_firstname":false,
		"applicant.applicant_lastname":false,
		"applicant.applicant_khmer_name":false,
		"applicant.sex":false,
		"applicant.applicant_date_birth":false,
		"applicant.applicant_origin_province_id#province_name":false,
		"applicant.high_school_id#high_school_name":false,
		"applicant_exam_room_beta.exam_center_id#province_id#province_name":false,
		"applicant_exam_room_beta.exam_center_id#exam_center_name":true
	},{
		"applicant_exam_room_beta.exam_center_id#exam_center_name":"='<?php echo $center_id?>'"
	});
}
</script>

<?php 
include("../footer.inc");
?>